import './Additional.scss'
import { useRequest } from 'alova/client';
import { Result, Button, Input, App } from 'antd'
import { Http } from '../../Utils/Api';
import { useState, } from 'react';
import { refreshStore } from '../../Config/zustand'

import { IsPassThroughMapping, WebCommonUrl } from '../../Config/theme'

const { TextArea } = Input


const ButtonMapping = {
    IsPassThroughMapping
}


const Additional = ({ data, Off }) => {

    const { updateRefresh } = refreshStore()
    const { type, init, params } = data
    const [ChartsName, setChartsName] = useState()
    const { notification } = App.useApp()
    const [Value, setValue] = useState()
    const [loading, setLoading] = useState(false)
    const { send } = useRequest(({ url, params }) => Http({ url, params }), { immediate: false })
    const onResetPassword = () => {
        send({ url: 'posUsersResetPassword', params: { uuid: init.uuid } }).then(() => {
            notification.success({ key: 'success', message: '操作成功', description: '密码重置成功!' })
            Off()
        })
    }
    const onSaveChartName = () => {
        send({ url: 'posJSONData', params: { uuid: `ChartStyle/${ChartsName}`, Content: JSON.stringify(data.init) } }).then(res => {
            notification.success({ key: 'success', message: '操作成功', description: 'VisCharts图标配置文件创建成功!' })
            Off()
        })
    }

    const onToExamine = (e) => {
        setLoading(true)
        // posBatchApprovalProject
        const data = init.map(key => ({ uuid: key, Remark: Value, ApprovalStatus: e }))
        send({ url: params.batchReviewUrl, params: data }).then(res => {
            notification.success({ key: 'success', message: '操作成功', description: '信息已审核完成!' })
            updateRefresh(new Date().getTime())
            Off()
        })
    }

    if (type === 'JumpLink') {
        return (
            <Result
                status="warning"
                title="您即将打开第三方链接,请确认"
                extra={[
                    <Button size='large' type="primary" key="close" onClick={Off}>取消</Button>,
                    <Button size='large' type="primary" key="jumpTo" onClick={() => window.open(data.url)}>跳转</Button>
                ]}
            />
        )
    }
    if (type === 'ResetPassword') {
        return (
            <Result
                status="warning"
                title="是否要重置现用密码,请确认"
                extra={[
                    <Button size='large' type="primary" key="close" onClick={Off}>取消</Button>,
                    <Button size='large' type="primary" key="jumpTo" onClick={onResetPassword}>确认</Button>
                ]}
            />
        )
    }
    if (type === 'SaveChartsConfig') {
        return (
            <Result
                status="warning"
                title="是否要重置现用密码,请确认"
                extra={[
                    <Input key='input' onChange={e => setChartsName(e.target.value)} style={{ marginBottom: 8 }} />,
                    <Button size='large' type="primary" key="jumpTo" onClick={onSaveChartName}>确认</Button>
                ]}
            />
        )
    }
    if (type === 'batchReviewTemp') {
        return (
            <Result
                status="warning"
                extra={[
                    <div key='batchReviewTemp' className='FormLabelClass' style={{ marginBottom: 16 }}>
                        <div>审核意见</div>
                        <TextArea placeholder='请输入审核意见' autoSize={{ minRows: 3, maxRows: 5 }} onChange={e => setValue(e.target.value)} />
                    </div>,
                    <div key='button'>
                        {ButtonMapping[params.batchReviewParams].map(({ value, label }) =>
                            <Button
                                key={value}
                                style={{ width: 120, margin: 16 }}
                                type="primary"
                                loading={loading}
                                onClick={() => onToExamine(value)}
                            >
                                {label}
                            </Button>
                        )}
                    </div>,
                ]}
            />
        )
    }
    if (type === 'OfficialAccount') {
        return (
            <div className='OfficialAccount'>
                <img src={WebCommonUrl + 'Common/WeChatOfficial.jpg'} alt="" />
            </div>
        )
    }

    if (type === 'BatchExcelModigy') {
        const { init, params } = data

        console.log(init, params)


        return (
            <div>批量excel修改</div>
        )
    }

}

export default Additional